package com.app.utils;

import com.app.model.AdminPermissionModel;
import com.app.model.CategoryModel;

import java.util.ArrayList;
import java.util.List;

public class FindChildrenUitl {

    //查询权限配置树
    public static List<AdminPermissionModel> findChildren(List<AdminPermissionModel> modelList, Integer pid) {
        List<AdminPermissionModel> personModelList = new ArrayList<>();
        for (int i = 0; i < modelList.size(); i++) {
            if (modelList.get(i).getPid() == pid) {
                AdminPermissionModel model = modelList.get(i);
                List<AdminPermissionModel> modelList1 = findChildren(modelList, model.getId());
                for (int j = 0; j < modelList1.size(); j++) {
                    if (modelList1 != null && modelList1.size() > 0) {
                        model.setChildList(modelList1);
                    }
                }
                personModelList.add(model);
            }
        }
        return personModelList;
    }

    //查询公用配置数据树
    public static List<CategoryModel> findCategoryChildren(List<CategoryModel> modelList, Integer pid) {
        List<CategoryModel> personModelList = new ArrayList<>();
        for (int i = 0; i < modelList.size(); i++) {
            if (modelList.get(i).getPid() == pid) {
                CategoryModel model = modelList.get(i);
                List<CategoryModel> modelList1 = findCategoryChildren(modelList, model.getId());
                for (int j = 0; j < modelList1.size(); j++) {
                    if (modelList1 != null && modelList1.size() > 0) {
                        model.setChild(modelList1);
                    }
                }
                personModelList.add(model);
            }
        }
        return personModelList;
    }

    public static List<AdminPermissionModel> findChildren2(List<AdminPermissionModel> modelList, Integer pid) {
        List<AdminPermissionModel> personModelList = new ArrayList<>();
        for (int i = 0; i < modelList.size(); i++) {
            if (modelList.get(i).getPid() == pid) {
                AdminPermissionModel model = modelList.get(i);
                List<AdminPermissionModel> modelList1 = findChildren(modelList, model.getId());
                for (int j = 0; j < modelList1.size(); j++) {
                    if (modelList1 != null && modelList1.size() > 0) {
                        model.setChildList(modelList1);
                    } else {
                        model.setChildList(new ArrayList<>());
                    }
                }
                personModelList.add(model);
            }
        }
        return personModelList;
    }
}
